package br.usp.ime.servicosusp;

import java.io.IOException;
import java.util.Vector;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import br.usp.ime.servicosusp.model.Local;
import br.usp.ime.servicosusp.model.Service;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class ViewCardapio extends Activity {
	/** Called when the activity is first created. */

	Service thisRestaurante;
	WebView mWebView;
	Integer servId;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_cardapio);
		
		mWebView = (WebView) findViewById(R.id.webview);
		
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.setWebViewClient(new WebViewClient(){
			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
				while (view.zoomOut()) {
				}
				;
				view.scrollTo(view.getWidth()/2, 0);
				Toast.makeText(view.getContext(), "Terminei", Toast.LENGTH_LONG).show();
			}
		});
		// Obter codigo do servi�o selecionado

		servId = getIntent().getExtras().getInt("ServiceID");
		thisRestaurante = Service.getServiceById(servId);

	}
	@Override
	protected void onStart() {
		super.onStart();
		mWebView.loadUrl(thisRestaurante.getLink());
	}
/*
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
			mWebView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public String limparConteudo(String conteudo) {
		String s = conteudo;

		if (conteudo.length() > 0) {

			while (s.indexOf("�") > 0) {
				Integer indice = s.indexOf("�");
				s = s.substring(0, indice - 1) + "a";
				s = s
						+ (indice < conteudo.length() ? conteudo.substring(
								indice + 1, conteudo.length())
								: conteudo.substring(conteudo.length(),
										conteudo.length()));
			}

		}
		return s.trim();
	}
*/
}